# this module is responcible for most of the row level formatting 
# on the project page.
module ProjectsHelper
  
  

  
  ##
  # creates the link to the project's teams list for the teams column
  def teams_column(record)
    '<b>' + link_to(record.teams.count.to_s + " teams", :controller => "teams", :action => 'for_project', :id => record.id) + '</b>'
    ##    http://0.0.0.0:3000/projects/6/nested?_method=get&associations=teams
  end

  
  ##
  # creates the link to the project's bug lists for the ug lists column
  def bug_lists_column(record)
    '<b>' + link_to(record.bug_lists.count.to_s + " lists", :controller => "bug_lists", :action => 'for_project', :id => record.id) + '</b>'
  end

  ##
  # creates the link to the project's admins list for the admins column
  def admins_column(record)
    '<b>' + link_to( pluralize(record.admins.count, 'admin'), :controller => "administrators", :action => 'for_project', :id => record.id) + '</b>'
    
  end
  
  ##
  # displays the number of projection weeks 
  def projection_weeks_column(record)
    pluralize(record.projection_weeks, 'week')
  end
  
  ##
  # creates the a clickable link to the projects generated website
  def name_column(record)
    '<b>' + link_to(record.name, :controller => '/sites/' + record.short_name + '/output/website/index.html' )    + '</b>'
  end
  
  
  ##
  # Displays the status of the project
  def status_column(record)
    
    if record.setup_required?
      '<b>' + link_to("Setup Required", {:controller => "projects", :id => record.id, :action => "show"}, {:style=>'color:#FF0000;'} )    + '</b>'
    elsif false == record.active
      link_to("disabled", {:controller => "projects", :id => record.id, :action => "show"})
    elsif record.generating?
      '<b>' + link_to("Generating", {:controller => "projects", :id => record.id, :action => "show"}, {:style=>'color:#00FF00;'})     + '</b>'   
    elsif true == record.active
      link_to("Pending Update", {:controller => "projects", :id => record.id, :action => "show"}) 
    end
  end
  
  ##
  # controlls the display of the edit control based on the
  # permissions of the logged in user
  
  def edit_control_column(record)
    if record.is_logged_in_project_administrator?
      '<b><a href="http://0.0.0.0:3000/projects/' + record.id.to_s + '/edit?_method=get"  class="edit action" id="projects-edit-' + record.id.to_s + '-link" position="replace">Edit</a></b>'  
    else
      "no soup"
    end
  end

end
